//
//  BaseBtn.m
//  ZITHER
//
//  Created by weixin on 2018/10/16.
//  Copyright © 2018年 weixn. All rights reserved.
//

#import "BaseBtn.h"

@implementation BaseBtn


-(instancetype)initializeFrame:(CGRect)frame NormalText:(NSString*)NormalText  NormalTextColor:(UIColor *)NormalTextColor SeleText:(NSString*)SeleText  SeleTextColor:(UIColor *)SeleTextColor   font:(NSInteger)font isBold:(BOOL)isBold{
    
    [self init].frame = frame;
    self.backgroundColor = [UIColor randomColor];

    if (NormalText != 0) {
        [self setTitle:NormalText forState:UIControlStateNormal];
        
        [self setTitleColor:NormalTextColor forState:UIControlStateNormal];
    }
    
    if (SeleText.length != 0) {
        [self setTitle:SeleText forState:UIControlStateSelected];
        
        [self setTitleColor:SeleTextColor forState:UIControlStateSelected];
    }
    
    
    if (font!=0) {
        if (isBold) {
            self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:font];
        }else{
            self.titleLabel.font = [UIFont systemFontOfSize:font];
        }
    }
    
    return self;
}

-(instancetype)initializeFrame:(CGRect)frame NormalText:(NSString*)NormalText NormalTextColor:(UIColor *)NormalTextColor SeleText:(NSString*)SeleText NormalImage:(NSString*)Normalimage SeleImage:(NSString*)Seleimage SeleTextColor:(UIColor *)SeleTextColor   font:(NSInteger)font isBold:(BOOL)isBold{
    
    [self init].frame = frame;
    self.backgroundColor = [UIColor randomColor];

    if (NormalText != 0) {
        [self setTitle:NormalText forState:UIControlStateNormal];
        
        [self setTitleColor:NormalTextColor forState:UIControlStateNormal];
    }
    
    if (SeleText.length != 0) {
        [self setTitle:SeleText forState:UIControlStateSelected];
        
        [self setTitleColor:SeleTextColor forState:UIControlStateSelected];
    }
    
    if (Normalimage.length !=0) {
        [self setImage:[UIImage imageNamed:Normalimage] forState:UIControlStateNormal];
    }
    if (Seleimage.length !=0) {
        [self setImage:[UIImage imageNamed:Seleimage] forState:UIControlStateSelected];
    }
    
    if (font!=0) {
        if (isBold) {
            self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:font];
        }else{
            self.titleLabel.font = [UIFont systemFontOfSize:font];
        }
    }
    
    return self;
}

/** 纯图片 */
-(instancetype)initializeFrame:(CGRect)frame NormalImage:(NSString*)Normalimage SeleImage:(NSString*)Seleimage{
    
    [self init].frame = frame;
    self.backgroundColor = [UIColor randomColor];

    if (Normalimage.length !=0) {
        [self setImage:[UIImage imageNamed:Normalimage] forState:UIControlStateNormal];
    }
    if (Seleimage.length !=0) {
        [self setImage:[UIImage imageNamed:Seleimage] forState:UIControlStateSelected];
    }
    
    return self;
}

/** 纯图片(新) */
+(instancetype)initCustomBtn:(NSArray*)images{
    BaseBtn *btn = [BaseBtn buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor randomColor];

    if (images.count>0) {
        [btn setImage:[UIImage imageNamed:images[0]] forState:UIControlStateNormal];
    }
    if (images.count >1) {
        [btn setImage:[UIImage imageNamed:images[1]] forState:UIControlStateSelected];
    }
    return btn;
}
+(instancetype)initCustomBtnTitlestype:(NSArray*)Titles color:(NSArray*)colors{
    
    BaseBtn *btn = [BaseBtn buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor randomColor];
    
    if (Titles.count>0) {
        [btn setTitle:Titles[0] forState:UIControlStateNormal];
    }
    
    if (Titles.count >1) {
        [btn setTitle:Titles[1] forState:UIControlStateSelected];
    }
    
    if (colors.count>0) {
        [btn setTitleColor:colors[0] forState:UIControlStateNormal];
    }
    
    if (colors.count>1) {
        [btn setTitleColor:colors[1] forState:UIControlStateSelected];
    }
    
    
    return btn;

}


/** 图+文字(新) */
+(instancetype)initCustomBtnImageAndTitles:(NSArray*)Titles images:(NSArray*)images color:(NSArray*)colors{
    BaseBtn *btn = [BaseBtn buttonWithType:UIButtonTypeCustom];
    btn.backgroundColor = [UIColor randomColor];
    
    if (Titles.count>0) {
        [btn setTitle:Titles[0] forState:UIControlStateNormal];
    }
    
    if (Titles.count >1) {
        [btn setTitle:Titles[1] forState:UIControlStateSelected];
    }
    
    if (colors.count>0) {
        [btn setTitleColor:colors[0] forState:UIControlStateNormal];
    }
    
    if (colors.count>1) {
        [btn setTitleColor:colors[1] forState:UIControlStateSelected];
    }
    
    if (images.count>0) {
        [btn setImage:[UIImage imageNamed:images[0]] forState:UIControlStateNormal];
    }
    if (images.count >1) {
        [btn setImage:[UIImage imageNamed:images[1]] forState:UIControlStateSelected];
    }
    
    return btn;
}
/** 添加点击事件 */
-(RACSignal *)addTag{
    return [self rac_signalForControlEvents:(UIControlEventTouchUpInside)] ;
//    @weakify(self);
//
//    [subscribeNext:^(__kindof UIControl * _Nullable x) {
//        @strongify(self);
//
//    }];
}


-(void)setLocalImage:(NSString*)url{
    NSString *str = [NSString stringWithFormat:@"%@%@",Main_Token_Model_MANAGER.postfixIcon,url];
    [self setImage:[UIImage imageNamed:str] forState:UIControlStateNormal];
}

@end
